/*
 * Copyright (c) 2020. vipyinzhiwei <vipyinzhiwei@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.samples.apps.library_common.extension

import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.google.samples.apps.library_common.utils.glide.ImageLoaderUtils


fun ImageView.loadLv(url: String?) {
    ImageLoaderUtils.displayDefault(this, url)
}

/**
 * Glide加载图片
 *
 * @param url 图片地址
 */
fun ImageView.load(url: String?, isCache: Boolean = true) {
    ImageLoaderUtils.display(this, url, isCache)
}

/**
 * Glide加载图片
 *
 * @param url 图片地址
 */
fun ImageView.loadDefault(url: String?) {
    ImageLoaderUtils.displayDefault(this, url)
}

/**
 * Glide加载图片
 *
 * @param url 图片地址
 */
fun ImageView.loadXY(url: String?) {
    ImageLoaderUtils.displayXY(this, url)
}

/**
 * Glide加载图片
 *
 * @param res 图片地址
 */
fun ImageView.load(res: Int) {
    ImageLoaderUtils.display(this, res)
}

/**
 * 头像
 */
fun ImageView.loadAvatar(res: Int) {
    ImageLoaderUtils.displayAvatar(this, res)
}

/**
 * 头像
 */
fun ImageView.loadAvatar(url: String?) {
    ImageLoaderUtils.displayAvatar(this, url)
}


//fun ImageView.displayFillet(res: Int, radius: Int) {
//    ImageLoaderUtils.displayFillet(this, res)
//}
/**
 * 圆角
 */
fun ImageView.loadFillet(url: String?, radius: Int) {
    ImageLoaderUtils.displayFillet(this, url, radius)
}


/**
 * Glide加载图片，可以定义配置参数。
 *
 * @param url 图片地址
 * @param options 配置参数
 */
fun ImageView.load(url: String?, options: RequestOptions.() -> RequestOptions) {
    Glide.with(this.context).load(url).apply(RequestOptions().options()).into(this)
}